package com.algorithm.one2fifty;

/**
 * @author tuzhijin
 * @version Id: SearchInsert_35.java, v 0.1 2021/6/5 下午9:17 tuzhijin Exp $$
 */
public class SearchInsert_35 {

    public static void main(String[] args) {
        int[] nums = {1, 3, 5, 6};
        int target = 5;
        System.out.println(searchInsert(nums, target));
    }

    public static int searchInsert(int[] nums, int target) {
        int l = 0, r = nums.length - 1;
        while (l <= r) {
            int mid = l + (r - l) / 2;
            if (nums[mid] < target) {
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        return l;
    }

}
